from flask_apscheduler.scheduler import APScheduler


class SchedulerUtil:
    _instance = None

    def __new__(cls):
        if not cls._instance:
            cls._instance = super().__new__(cls)
            cls._instance.scheduler = APScheduler()
        return cls._instance

    @staticmethod
    def get_scheduler():
        scheduler = SchedulerUtil()._instance.scheduler
        # 直接应用调度器配置
        scheduler.timezone = 'Asia/Shanghai'
        scheduler.api_enabled = True
        scheduler.api_prefix = '/scheduler'
        scheduler.allowed_hosts = ['*']
        scheduler.executors = {'default': {'type': 'threadpool', 'max_workers': 10}}
        return scheduler
